package com.hspjava.Homework;

public class Homework01 {
    public static void main(String[] args) {
        try {
            String s = "abcdefg";
            System.out.println(reverse(s, 0, 6));
        } catch (Exception e) {
            System.out.println(e.getMessage());
        }
    }
    public static String reverse(String str, int start, int end) {
        if ( !(str != null && start >= 0 && end < str.length() )) {
            throw new RuntimeException("参数不正确");
        }
        char[] p = str.toCharArray();
        for (int l = start, r = end; l <= r; l++, r-- ) {
            char tmp = p[l];
            p[l] = p[r];
            p[r] = tmp;
        }
        return new String(p);
    }
}
